
cap cd "/Users/leyou/Dropbox/Haiti_trade/ReplicationPkg/"
*cap cd "C:\Users\snaidu\Documents\Dropbox\Haiti_Lauren\replication files\Haiti_trade_20160307\Haiti_trade\"
clear all
set mem 30g
*set matsize 11000
*set maxvar 30000
set more off
use "01_Data/02_Clean/price_final.dta", clear






egen pid =group(product)
destring year, replace

gen yearmo = year *100 + month
*keep if yearmo < 200701
sort pid yearmo
bys pid: gen date_n = _n
list yearmo date_n
xtset pid date_n
levelsof yearmo, local(period)
foreach var of local period{

	gen yearmo_`var' = yearmo==`var'

}



lgraph price_delta_log    date_n if date_n>=30 & date_n<=70, by(highcoup) xline(38 64)


gen price_logch98 = price_log- .98*L.price_log
xtreg price_logch98 coupXautoc coupXquake yearmo_*, fe cluster(pid)
keep pid yearmo_* coupX* price_log yearmo date_n
eststo clear
xtabond2 price_log l(1/4).price_log coupXautoc coupXquake yearmo_* ,   gmmstyle(price_log coupXautoc) ivstyle( coupXquake yearmo_*,p)  robust noleveleq nodiffsargan
eststo
estadd local instruments="All Lags"
xtabond2 price_log l(1/4).price_log coupXautoc coupXquake yearmo_* ,   gmmstyle(price_log coupXautoc, laglimits(1 10)) ivstyle( coupXquake yearmo_*,p)  robust noleveleq nodiffsargan
eststo
estadd local instruments="Lags 1-10"
xtabond2 price_log l(1/4).price_log coupXautoc coupXquake yearmo_* ,   gmmstyle(price_log coupXautoc, laglimits(2 10)) ivstyle( coupXquake yearmo_*,p)  robust noleveleq nodiffsargan
eststo
estadd local instruments="Lags 2-10"
xtabond2 price_log l(1/4).price_log coupXautoc coupXquake yearmo_* ,   gmmstyle(price_log coupXautoc, laglimits(1 8)) ivstyle( coupXquake yearmo_*,p)  robust noleveleq nodiffsargan
eststo
estadd local instruments="Lags 1-8"
xtabond2 price_log l(1/4).price_log coupXautoc coupXquake yearmo_* ,   gmmstyle(price_log coupXautoc, laglimits(2 8)) ivstyle(coupXquake yearmo_*,p)  robust noleveleq nodiffsargan
eststo
estadd local instruments="Lags 2-8"
esttab using "ARtable_V2.tex", keep(coupXautoc ) se stats(instruments, label("Instruments")) star(* .1 ** .05 *** .01) replace fragment 
type "ARtable_V2.tex"




estimates store e5
file write myfile1 "&" %7.2f (_b[dem]/(1-_b[L.y]-_b[L2.y]-_b[L3.y]-_b[L4.y]))
testnl _b[dem]/(1-_b[L.y]-_b[L2.y]-_b[L3.y]-_b[L4.y])=0
file close myfile1
file write myfile2 "& [" %7.3f (r(p)) "] "
file write myfile3 "&" %7.3f (_b[L.y]+_b[L2.y]+_b[L3.y]+_b[L4.y])
testnl (1-_b[L.y]-_b[L2.y]-_b[L3.y]-_b[L4.y])=0
file write myfile4 "& [" %7.3f (r(p)) "] "

stop

